
<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <!-- <el-button type="primary" icon="el-icon-plus" @click="add"></el-button> -->
        <!-- <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          :disabled="selection.length == 0"
          @click="batchDel"
        ></el-button> -->
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-input
            v-model="search.keyword"
            style="width: 170px"
            placeholder="请输入标题搜索"
            clearable
          >
          </el-input>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upSearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable
        ref="table"
        :apiObj="apiObj"
        @selection-change="selectionChange"
        stripe
      >
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column
          label="编号"
          prop="id"
          width="80"
          sortable
        ></el-table-column>
        <el-table-column
          label="文稿标题"
          prop="articleTitle"
          width="150"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="关键字"
          prop="keyword"
          width="150"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="中文摘要"
          prop="abstractZn"
          width="150"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="所属领域"
          prop="fieldName"
          width="100"
        ></el-table-column>
        <el-table-column
          label="所属栏目"
          prop="columnName"
          width="100"
        ></el-table-column>
        <el-table-column label="文稿状态" prop="articleStatus" width="100">
          <template #default="scope">
            <el-tag
              v-if="scope.row.articleStatus == 0"
              type="info"
              disable-transitions
              >未提交</el-tag
            >
            <el-tag
              v-if="scope.row.articleStatus == 1"
              type="primary"
              disable-transitions
              >审核中</el-tag
            >
            <el-tag
              v-if="scope.row.articleStatus == 2"
              type="success"
              disable-transitions
              >审核通过</el-tag
            >
            <el-tag
              v-if="scope.row.articleStatus == 3"
              type="danger"
              disable-transitions
              >未通过</el-tag
            >
            <el-tag
              v-if="scope.row.articleStatus == 4"
              type="info"
              disable-transitions
              >已退稿</el-tag
            >
            <el-tag
              v-if="scope.row.articleStatus == 5"
              type="info"
              disable-transitions
              >已过期</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column
          label="提交时间"
          prop="submitDate"
          width="180"
        ></el-table-column>
        <el-table-column label="操作" fixed="right" align="right" width="170">
          <template #default="scope">
            <!-- <div
              v-if="
                scope.row.articleStatus == 0 || scope.row.articleStatus == 4
              "
            >
              <el-button-group>
                <el-button
                  size="small"
                  @click="tableEdit(scope.row, scope.$index)"
                  >编辑</el-button
                >
                <el-popconfirm
                  title="确定删除吗？"
                  confirm-button-type="danger"
                  confirm-button-text="确定"
                  @confirm="tableDel(scope.row, scope.$index)"
                >
                  <template #reference>
                    <el-button type="danger" size="small">删除</el-button>
                  </template>
                </el-popconfirm>
                <el-popconfirm
                  title="确定提交吗？"
                  confirm-button-type="success"
                  confirm-button-text="确定"
                  @confirm="tableSubmit(scope.row, scope.$index)"
                >
                  <template #reference>
                    <el-button type="success" size="small">提交</el-button>
                  </template>
                </el-popconfirm>
              </el-button-group>
            </div> -->
            <el-button
              size="small"
              v-if="scope.row.articleStatus == 3"
              type="success"
              @click="callback(scope.row, scope.$index)"
              >回复</el-button
            >
            <el-button size="small" v-else @click="cat(scope.row, scope.$index)"
              >查看回复</el-button
            >
            <el-button size="small" @click="tableShow(scope.row, scope.$index)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
  <save-dialog
    v-if="dialog.save"
    ref="saveDialog"
    @success="handleSuccess"
    @closed="dialog.save = false"
  >
  </save-dialog>
  <el-dialog
    v-model="dialog.callback"
    :size="560"
    title="退稿回复"
    direction="rtl"
    destroy-on-close
  >
    <el-form
      :model="form"
      :rules="rules"
      label-width="80px"
      label-position="right"
      ref="dialogForm2"
    >
      <el-form-item label="退稿建议" prop="callbackAdvise">
        <el-input
          type="textarea"
          rows="5"
          v-model="form.callbackAdvise"
          placeholder="请输入驳回理由或者修改建议"
          maxlength="500"
          show-word-limit
          clearable
          :disabled="disabled"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div>
        <el-button
          v-if="dialog.cat"
          type="success"
          :loading="isSaveing"
          @click="reject()"
          >提 交</el-button
        >
        <el-button @click="dialog.callback = false">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import saveDialog from "./save";
export default {
  name: "articleAdvice",
  components: {
    saveDialog,
  },
  data() {
    return {
      dialog: {
        cat: false,
        save: false,
        callback: false,
      },
      disabled: false,
      form: {
        callbackAdvise: "",
      },
      showGrouploading: false,
      apiObj: this.$API.article.advicePage,
      selection: [],
      articleId: null,
      search: {
        keyword: "",
      },
      rules: {
        callbackAdvise: [{ required: true, message: "退稿建议不能为空" }],
      },
    };
  },
  watch: {},
  mounted() {},
  methods: {
    //搜索
    upSearch() {
      this.$refs.table.upData(this.search);
    },
    callback(row) {
      this.dialog.cat = true;
      this.articleId = row.id;
      this.dialog.callback = true;
      this.disabled=false;
    },
    async cat(row) {
      this.dialog.cat = false;
      this.dialog.callback = true;
      this.disabled=true;
      var res = await this.$API.article.callbackDetail.get({id: row.id});
      this.form = res.data;
    },
    //退稿回复
    async reject() {
      this.$refs.dialogForm2.validate(async (valid) => {
        if (valid) {
          var reqData = new FormData();
          reqData.append("id", this.articleId);
          reqData.append("callbackAdvise", this.form.callbackAdvise);
          var res = await this.$API.article.callback.post(reqData);
          if (res.code == "200") {
            this.$refs.table.refresh();
            this.dialog.callback = false;
            this.$message.success("回复完成");
          } else {
            this.$alert(res.message, "提示", { type: "error" });
          }
        } else {
          return false;
        }
      });
    },
    //添加
    add() {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open();
      });
    },
    //编辑
    tableEdit(row) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("edit").setData(row);
      });
    },
    //详情
    tableShow(row) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("show").setData(row);
      });
    },
    //本地更新数据
    handleSuccess(data, mode) {
      if (mode == "add") {
        this.$refs.table.refresh();
      } else if (mode == "edit") {
        this.$refs.table.refresh();
      }
    },
    //表格选择后回调事件
    selectionChange(selection) {
      this.selection = selection;
    },
    //删除
    async tableDel(row) {
      var reqData = new FormData();
      reqData.append("id", row.id);
      var res = await this.$API.article.delete.post(reqData);
      if (res.code == 200) {
        this.$refs.table.refresh();
        this.$message.success("删除成功");
      } else {
        this.$alert(res.message, "提示", { type: "error" });
      }
    },
    //提交
    async tableSubmit(row) {
      var reqData = new FormData();
      reqData.append("id", row.id);
      var res = await this.$API.article.submit.post(reqData);
      if (res.code == 200) {
        this.$refs.table.refresh();
        this.$message.success("提交成功");
      } else {
        this.$alert(res.message, "提示", { type: "error" });
      }
    },
    //批量删除
    async batchDel() {
      this.$confirm(
        `确定删除选中的 ${this.selection.length} 个选项吗？`,
        "提示",
        {
          type: "warning",
          confirmButtonText: "确定",
          confirmButtonClass: "el-button--danger",
        }
      )
        .then(async () => {
          const loading = this.$loading();
          let ids = this.selection.map((item) => {
            return item.id;
          });
          var reqData = new FormData();
          reqData.append("ids", ids);
          var res = await this.$API.article.batchDelete.post(reqData);
          if (res.code == 200) {
            this.$refs.table.refresh();
            this.$message.success("删除成功");
          } else {
            this.$alert(res.message, "提示", { type: "error" });
          }
          loading.close();
        })
        .catch(() => {});
    },
  },
};
</script>
